package org.lfh.wintersun.config;

import jakarta.annotation.Resource;
import org.lfh.wintersun.web.user.entity.SysUserDetails;
import org.lfh.wintersun.web.user.entity.SysUserEntity;
import org.lfh.wintersun.web.user.service.SysUserService;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class CustomUserDetailsService implements UserDetailsService {

    @Resource
    private SysUserService userService;

    @Override
    public SysUserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        SysUserEntity user = userService.findByUsername(username);
        if (user == null) {
            throw new UsernameNotFoundException("User not found");
        }
        return new SysUserDetails(user);
    }
}
